﻿var Whale = {
    pageInit: function () {

    },
    dataSource: function (setting) {
        var pageSize = setting.pageSize != undefined && setting.pageSize != null && setting.pageSize > 0 ? setting.pageSize : 0;
        return {
            transport: {
                read: function (options) {
                    var sortField = "";
                    var sortDir = "";
                    if (typeof options.data.sort != "undefined" && options.data.sort.length > 0) {
                        sortField = options.data.sort[0].field;
                        sortDir = options.data.sort[0].dir;
                    }
                    var data = {
                        pageSize: pageSize,
                        pageIndex: typeof options.data.page == "undefined" ? 0 : options.data.page - 1,
                        sortField: sortField,
                        sortDir: sortDir
                    };
                    if (setting.getParameters != undefined)
                        data = $.extend(data, setting.getParameters());
                    var response = Whale.Remote.GetCollection({
                        url: setting.url,
                        parameters: data
                    });
                    if (response != null && response.Success) {
                        options.success(response);
                    } else if (response != null)
                        options.error(response.Message);
                    else
                        options.error("error.");
                }
            },
            schema: {
                data: function (result) {
                    return (result != null && result.Total > 0) ? result.Data : [];
                },
                total: function (result) {
                    return result != null ? result.Total : 0;
                }
            },
            error: function (e) {
                if (wndGeneralInformation != null) {
                    wndGeneralInformation.content(e.xhr).open();
                }
            },
            pageSize: pageSize,
            serverPaging: true,
            serverFilter: setting.serverFilter,
            serverSorting: setting.serverSorting
        };
    }
};

Whale.pageInit();

function CancelGeneralEdit() {
    if (wndGeneralEdit != null) {
        wndGeneralEdit.close();
    }
    return false;
}

///显示通用状态图标
function GeneralStatus(status) {
    var html = "";
    switch (status) {
        case 1:
            html += "<span class='k-icon k-i-tick'><span>";
            break;
        case 2:
            html += "<span class='k-icon k-i-cancel'><span>";
            break;
        default:
            html += "<span class='k-icon k-i-close'><span>";
            break;
    }
    return html;
}

///显示通用是否图标
function GeneralBoolean(b) {
    return b ? "YES" : "NO";
    //return "<span class='k-icon k-i-" + (b ? "tick" : "close") + "'><span>";
}
